<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Web Components</title>
  </head>
  <body>
    <hover-pop>
      <button>测试</button>
      <div slot="content">
        <p>弹窗内容测试1</p>
      </div>
    </hover-pop>

    <hover-pop>
      <button>测试</button>
      <div slot="content">
        <p>弹窗内容测试2</p>
      </div>
    </hover-pop>
    <!-- 以下是组件 -->
    <template id="hover-pop">
      <div class="tooltip-div">
        <i class="layui-icon layui-icon-tips-fill"></i>
        <slot></slot>
        <!-- 旋转三角形 -->
        <div class="triangle"></div>
        <div class="tooltip-box">
          <slot name="content"> 测试测试 </slot>
        </div>
      </div>
      <style>
        /* hover浮动弹窗 */
        .tooltip-div {
          position: relative;
          width: fit-content;
        }
        .tooltip-box {
          width: 500px;
          height: fit-content;
          background-color: white;
          position: absolute;
          padding: 20px;

          top: 50%;
          left: calc(100% + 10px);
          transform: translateY(-50%);
          border-radius: 8px;
          box-shadow: 4px 4px 4px 4px rgba(0, 0, 0, 0.1);
        }

        .tooltip-div .triangle {
          width: 10px;
          height: 10px;

          position: absolute;
          left: 100%;
          top: 50%;
          transform: translateY(-50%);
          overflow: hidden;
        }
        .tooltip-div .triangle::after {
          content: '';
          width: 10px;
          height: 10px;
          position: absolute;
          left: 70%;
          top: 50%;
          transform: translateY(-50%) rotate(45deg);

          background: #fff;
          box-shadow: 0px 0px 2px 1px rgba(0, 0, 0, 0.1);
        }
        /* 设置hover才展示 */
        .tooltip-box,
        .triangle {
          visibility: hidden;
        }
        .tooltip-div:hover > .tooltip-box,
        .tooltip-div:hover > .triangle {
          z-index: 1000;
          visibility: visible;
        }
        .tooltip-div:hover > .triangle {
          z-index: 1100;
        }

        /* 信息内容的样式 */
        .ticket-body {
          font-family: Source Han Sans CN, Source Han Sans CN;
          font-weight: 400;
          font-size: 14px;
          color: #4e5969;
        }
        .ticket-body .verify-txt {
          font-family: Source Han Sans CN, Source Han Sans CN;
          font-weight: 400;
          font-size: 14px;
          color: var(--fail-color);
          margin-bottom: 20px;
        }
        .ticket-body .body-info {
          padding: 20px;

          background: #f8f8f8;
          border-radius: 10px;
        }
        .ticket-body .body-info .info-item {
          display: flex;
          align-items: center;
          margin-bottom: 10px;
        }
        .ticket-body .body-info .info-label {
          width: 100px;
          font-family: Source Han Sans CN, Source Han Sans CN;
          font-weight: 400;
          font-size: 14px;
          color: #86909c;
          margin-right: 8px;
        }
        .ticket-body .body-info .info-txt {
          font-family: Source Han Sans CN, Source Han Sans CN;
          font-weight: 400;
          font-size: 14px;
          color: #1d2129;
        }
        .ticket-footer {
          display: flex;
          justify-content: flex-end;
        }
      </style>
    </template>
    <!-- 以下是逻辑 -->
    <script src="./components/HoverPop.js"></script>
    <script></script>
  </body>
</html>
